Here is the latest installment in my exploration of the List element. :)
Given this example code, I would expect to see two lists in a dialog box with the items "a", "b", and "c" in one of them and "1", "2", and "3" in the other.
void addListA(DB x)
{
string AAA[] = {"a", "b", "c"}
list(x, "List A", 3, AAA)
}
void addListB(DB x)
{
string BBB[] = {"1", "2", "3"}
list(x, "List B", 3, BBB)
}
DB box = create("Lists")
addListA(box)
addListB(box)
show box
But I don't! Both lists end up with the "1", "2", and "3" entries. It appears that even though the two arrays are local to each function, the strings in the list box end up sharing memory space somehow.
To get the two lists to display their own items I must declare the two string arrays in the same context. I am getting the distict impression that static arrays do not work very well in DXL.
This post is not marked as a question, as I haven't really asked one, but if anyone has a better explanation than "Yeah, arrays don't really work the way you expect them to", I'd love to hear it.
--
Scott
SystemAdmin - Mon Oct 05 15:03:58 EDT 2009 |
Re: List memory reuse? SystemAdmin - Mon Oct 05 16:28:42 EDT 2009
In DOORS 7.1, both lists display 1, 2, 3. In DOORS 8.3 and DOORS 9.2, the top list is a, b, c and the bottom list is 1, 2, 3. Looks like a defect in DOORS 7.1.
|
Re: List memory reuse? SystemAdmin - Mon Oct 05 17:13:02 EDT 2009 SystemAdmin - Mon Oct 05 16:28:42 EDT 2009
In DOORS 7.1, both lists display 1, 2, 3. In DOORS 8.3 and DOORS 9.2, the top list is a, b, c and the bottom list is 1, 2, 3. Looks like a defect in DOORS 7.1.
I am using Doors 8.1.0.0, so I am guessing the fix came shortly after that.
|
Re: List memory reuse? llandale - Tue Oct 13 13:07:51 EDT 2009
It is not 'fixed'.
The actual creation of the list takes place when you 'realize' the DB, which is implicit in the 'show' command. That is, the 'list' command just associates the DBE with the address of the string list (AAA and BBB), it doesn't assign the values until the box is 'realized'.
When you 'show' the box, notice that the local declarations of AAA and BBB are both lost since they are in functions and their data is on the stack, and you get whatever gargage is in that location when the 'show' is issued. If you had other functions that dealt with strings and called them after your addListA/B calls, you'd find your boxes are populated with lots of wierd stuff. As it is, your simplistic DXL leaves the stack prestine and you see your values.
The only real solution I've come up with is to declare a few huge lists in the main program, populate them inside the functions along with the true 'size', which is how many entries you inserted. That is, declare AAA and BBB perhaps at size 100 in the main, and in your functions do this:
int Size = 0
AAA[Size++] = "1"
AAA[Size++] = "2"
AAA[Size++] = "3"
int NumVisible = 4
list(x, "List A", NumVisible, AAA, Size).
I made a feeble effort at declaring the vectors in the function then inserting them into a global Skip list, but that didn't work since the Vector itself is on the stack and is lost.
|